clear all
close all
clc
tic
load('./temp/config.mat', 'config');

% if config.if_server
%     setenv('LD_LIBRARY_PATH', ['/usr/lib/x86_64-linux-gnu:/usr/local/lib:/usr/lib:' getenv('LD_LIBRARY_PATH')]);
% end

config.res_pool_root = './temp/res_pool/';

classifier_bank_path = dir( [config.sub_model_root  '*.yml'] );

%%

if isempty( dir( config.res_pool_root ) ), system(['mkdir "' config.res_pool_root '"']);end

dataset_n = length( config.datasets );

for i = 1:dataset_n
    
    dataset_folder = [config.res_pool_root config.datasets{i}.name '/'];
    
    if isempty( dir( dataset_folder ) ), system(['mkdir "' dataset_folder '"']);end
    
    for j = 1:length( classifier_bank_path )
        
        classifier_name = classifier_bank_path(j).name;
        
        folder_name = classifier_name(1:end-9);
        
        save_folder = [dataset_folder folder_name '/'];
        
        if isempty( dir( save_folder ) ), system(['mkdir "' save_folder '"']);end
        
        res_list_name = [save_folder 'list.txt'];
        
        writeResList( config.datasets{i} , save_folder,res_list_name);
        
        if config.if_server
            
            src_name = [ config.file_list_root config.datasets{i}.name '_src.txt'];
            gt_name =  [ config.file_list_root config.datasets{i}.name '_gt.txt'];
            commend = [...
                    '"./interface/mainInterface" -c ' ...
                    '-s "' src_name '" ' ...
                    '-g "' gt_name '" ' ...
                    '-v ' config.feature_str ' ' ...
                    '-r ' res_list_name ' ' ...
                    '-m ' [config.sub_model_root classifier_name(1:end-8)]];
            system( commend );
        else
            src_name = [ config.file_list_root config.datasets{i}.name '_src.txt'];
            gt_name =  [ config.file_list_root config.datasets{i}.name '_gt.txt'];
            commend = [...
                    '"./interface/Single.exe" -c ' ...
                    '-s "' src_name '" ' ...
                    '-g "' gt_name '" ' ...
                    '-v ' config.feature_str ' ' ...
                    '-r ' res_list_name ' ' ...
                    '-m ' [config.sub_model_root classifier_name(1:end-8)]];
            system( commend );
        end
        
        %break;
    end
    %break;
end

save('./temp/classifier_bank','classifier_bank_path')